﻿using Deployment.Data.Variable;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Deployment.Data.UI.Dialogs.Variable
{
    /// <summary>
    /// Interaction logic for VariablesDialog.xaml
    /// </summary>
    public partial class VariablesDialog : Window, INotifyPropertyChanged
    {

        public static readonly DependencyProperty EnvironmentsProperty =
            DependencyProperty.Register("Environments",
                typeof(Data.Environment.EnvironmentsFile),
                typeof(VariablesDialog));

        public static readonly DependencyProperty VariablesPropery =
            DependencyProperty.Register("Variables",
                typeof(Data.Variable.VariablesFile),
                typeof(VariablesDialog));

        public static readonly DependencyProperty VariablesFileProperty =
            DependencyProperty.Register("VariablesFilePath",
                typeof(string),
                typeof(VariablesDialog));
        public event PropertyChangedEventHandler PropertyChanged;

        private void SetValueDp(DependencyProperty property, object value)
        {
            SetValue(property, value);
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(property.Name));
        }

        public VariablesDialog(string variablesFile = null)
        {
            InitializeComponent();

            DataContext = this;
            if (!string.IsNullOrEmpty(variablesFile))
            {
                Variables = Data.Variable.VariablesFile.LoadFromFile(variablesFile);
                VariablesFilePath = variablesFile;
            }
            else
            {
                Variables = new VariablesFile();
            }
            
        }

        public Data.Variable.VariablesFile Variables
        {
            get { return (Data.Variable.VariablesFile)GetValue(VariablesPropery); }
            set 
            { 
                SetValueDp(VariablesPropery, value);
                EditorControl.Variables = value;
            }
        }

        public Data.Environment.EnvironmentsFile Environments
        {
            get { return (Data.Environment.EnvironmentsFile)GetValue(EnvironmentsProperty); }
            set 
            { 
                SetValueDp(EnvironmentsProperty, value);
                EditorControl.Environments = value;
            }
        }

        public string VariablesFilePath 
        {
            get { return (string)GetValue(VariablesFileProperty); }
            set { SetValueDp(VariablesFileProperty, value); }
        }

        
    }
}
